import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
import LocalCache from '@/utils/cache';
// import HomeView from '../views/HomeView.vue';
// import { firstRoute } from '@/utils/map-menu';

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    redirect: 'main'
  },
  {
    path: '/login',
    component: () => import('@/views/login/index.vue')
  },
  {
    path: '/main',
    component: () => import('@/views/main/index.vue')
  }
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
});

router.beforeEach((to) => {
  if (to.path !== '/login') {
    const token = LocalCache.getCache('token');
    if (!token) {
      return '/login';
    }

    // if (to.path === '/main') {
    //   console.log(firstRoute);
    //   return firstRoute?.path;
    // }
  }
});

export default router;
// git config --global user.name "marvinzyx"
// git config --global user.email "2771489986@qq.com"
